class MyPlugin {
    constructor(options) {
        this.options = options
    }
    apply(compiler) {
        console.log('pkugin start')
        compiler.hooks.emit.tap('MyPlugin', compilation => { //emit 为执行时机 挂载的钩子函数
            console.log(this, '==========')
            Object.keys(compilation.assets).map(item => {
                if (item.endsWith('.js')) {
                    const withOutComments = compilation.assets[item].source().replace(/\/\*\*+\*\//g, '')
                    compilation.assets[item] = {
                        source:() => withOutComments,
                        size:() => withOutComments.length
                    }
                }
            })
        })
    }
}

module.exports = MyPlugin;